package component

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commConfig"
	"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/Map"
	"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/TimeInterval"
	"time"
)

type timeIntervalService struct {
	timeInterval TimeInterval.TimeInterval
}

func (e *timeIntervalService) TestLastTime(entityType string) (bool, error) {
	configValue, err := commConfig.GetConfigParam("serverConfig")
	if err != nil {
		return false, err
	}

	// 取出全局配置参数
	entities := Map.GetMap(configValue, "entities", make(map[string]interface{}))
	data := Map.GetMap(entities, entityType, nil)
	if data == nil {
		return false, nil
	}

	publish := Map.GetBool(data, "publish", false)
	interval := Map.GetInt64(data, "interval", 1)

	if true != publish {
		return false, nil
	}

	// 测试时间间隔
	return e.timeInterval.TestLastTime(entityType, time.Now().UnixMilli(), interval*1000), nil
}
